package com.deparse.mydialog.listview;

import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ListView;
import android.widget.TextView;

import com.deparse.mydialog.R;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by Administrator on 2016/7/25.
 */
public class HideListTitleActivity extends BaseListActivity {
    private float mFirstY, mCurrentY;
    private int mTouchSlop;
    private int direction;
    private boolean mIsScrollToUp = false;
    private int mScreenY = 0;
    private int mListViewFirstItem = 0;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final ListView listView = getListView();
        final MyBaseAdapter adapter = getAdapter();
        List<String> data = getListData();
//        LayoutInflater layoutInflater = LayoutInflater.from(this);
//        View headerView = layoutInflater.inflate(R.layout.list_header_title1, null);
//        View headerView = layoutInflater.inflate(R.layout.list_header_title1, null);
//        listView.addHeaderView(headerView);
        mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();


//        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
//            @Override
//            public void onScrollStateChanged(AbsListView view, int scrollState) {
//
//            }
//
//            @Override
//            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
//
//                if (listView.getChildCount() > 0) {
//                    boolean isScrollToUp = false;
//                    View childAt = listView.getChildAt(firstVisibleItem);
//                    int[] location = new int[2];
//                    childAt.getLocationOnScreen(location);
//                    Log.d("onScroll", "firstVisibleItem= " + firstVisibleItem + " , y=" + location[1]);
//
//                    if (firstVisibleItem != mListViewFirstItem) {
//                        if (firstVisibleItem > mListViewFirstItem) {
//                            Log.e("--->", "向上滑动");
//                            isScrollToUp = true;
//                        } else {
//                            Log.e("--->", "向下滑动");
//                            isScrollToUp = false;
//                        }
//                        mListViewFirstItem = firstVisibleItem;
//                        mScreenY = location[1];
//                    } else {
//                        if (mScreenY > location[1]) {
//                            Log.i("--->", "->向上滑动");
//                            isScrollToUp = true;
//                        } else if (mScreenY < location[1]) {
//                            Log.i("--->", "->向下滑动");
//                            isScrollToUp = false;
//                        }
//                        mScreenY = location[1];
//                    }
//
//                    if (mIsScrollToUp != isScrollToUp) {
////                        onScrollDirectionChanged(mIsScrollToUp);
//                    }
//
//                    if (isScrollToUp) {
////                        top_parent.setVisibility(View.GONE);
//                    } else {
//
////                        top_parent.setVisibility(View.VISIBLE);
//
//
//                    }
//
//                }
//            }
//        });

//        listView.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                switch (event.getAction()) {
//                    case MotionEvent.ACTION_DOWN:
//                        mFirstY = event.getY();
//                        Log.d("mylog", "mFirstY=" + mFirstY);
//                        break;
//                    case MotionEvent.ACTION_MOVE:
//
//                        mCurrentY = event.getY();
//                        Log.d("mylog", "mCurrentY=" + mCurrentY);
//                        if (mCurrentY - mFirstY > mTouchSlop) {
//                            direction = 0;//down
//                        } else if (mFirstY - mCurrentY > mTouchSlop) {
//                            direction = 1;//up
//                        }
//                        if (direction == 0) {
//
//                            ObjectAnimator animator1 = ObjectAnimator.ofFloat(title, "alpha", 0, 1);
//                            animator1.setDuration(1000);
//                            animator1.start();
//                            title.setVisibility(View.VISIBLE);
//                        } else if (direction == 1) {
//
//
//                            ObjectAnimator animator = ObjectAnimator.ofFloat(title, "alpha", 1, 0);
//                            animator.setDuration(1000);
//                            animator.start();
////                            title.setVisibility(View.GONE);
//                        }
//
//                        break;
//                    case MotionEvent.ACTION_UP:
//
//                        break;
//                    default:
//                        break;
//                }
//                return false;
//            }
//        });

    }
}
